<template>
	<view class="allBac">
		<view class="headers">
			<view style="height: var(--status-bar-height);">
				<!-- app状态栏高度占位 -->
			</view>
			<view class="btns">
				<view class="servies" @click="toNote()" style="width: 22px;height: 22px;">
					<image style="width: 22px;height: 22px;" src="@/static/img/my_title_btn_notice.png" alt=""
						width="100%" height="100%">
				</view>
				<view class="setting" @click="goSetting()" style="width: 22px;height: 22px;">
					<image style="width: 22px;height: 22px;" src="@/static/img/my_title_btn_set.png" alt="" width="100%"
						height="100%">
				</view>
			</view>
			<view class="userInfo">
				<view class="basicInfo" v-if="!userInfo">
					<view class="head_photo" @click="toLogin()">
						<image style="width: 140rpx; height: 140rpx;" src="@/static/c1.png" alt="">
					</view>
					<view class="user_name" @click="toLogin()">
						登录/注册
					</view>
				</view>
				<view class="basicInfo" v-else>
					<view class="head_photo">
						<image style="width: 140rpx; height: 140rpx;border-radius: 70rpx;" :src="userInfo2.img" alt="">
					</view>
					<view class="user_name">
						<view class="name_detial">
							{{userInfo2.companyName}}
						</view>
					</view>
				</view>
				<view class="userOperate">
					<view class="operate1" @click="toMyWallet()">
						<image style="width: 40px;height: 40px;" src="@/static/img/my_function_wallet.png" mode="">
						</image>
						<view class="text">
							我的钱包
						</view>
					</view>
					<view class="operate1" @click="toOrganization()">
						<image style="width: 40px;height: 40px;" src="@/static/img/my_function_agency.png" mode="">
						</image>
						<view class="text">
							我的机构
						</view>
					</view>
					<view class="operate1" @click="toCustomer()">
						<image style="width: 40px;height: 40px;" src="@/static/img/my_function_customer.png" mode="">
						</image>
						<view class="text">
							我的顾客
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getAdminInfo,
		getInstitution
	} from '@/utils/api.js'
	export default {
		data() {
			return {
				userInfo: false,
				photo: '',
				status: '', //判断实名认证
				dataList: [],
				token: '',
				userInfo2: {},
				Institution: true
			}
		},
		onShow() {
			try {
				const token = uni.getStorageSync('user');
				console.log(token, 'token');
				if (token) {
					console.log(token);
					this.token = token.token
					this.userInfo = true
					getAdminInfo().then((res) => {
						if (res.data.meta.status == 200) {
							this.userInfo2 = res.data.data
							
							uni.setStorageSync('xddtest',this.userInfo2.companyName)
							const xddtest = uni.getStorageSync("xddtest")
							console.log(xddtest,'????????????');
						}
					})
					getInstitution().then((res) => {
						if (res.data.meta.status == 200) {
							if (res.data.data.length == 0) {
								this.Institution = false
							}
						}
					})
				}
			} catch (e) {
				//TODO handle the exception
			}
		},
		onUnload() {

		},
		methods: {
			goLogin() {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			},
			cancel() {
				this.show = false
			},
			toCustomer() {
				uni.navigateTo({
					url: '/pages/my/customer/customer'
				})
			},
			toNote() {
				uni.navigateTo({
					url: '/pages/my/notice/notice'
				})
			},
			toLogin() {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			},
			goSetting() {
				uni.navigateTo({
					url: '/pages/my/setting/setting'
				})
			},
			toMyWallet() {
				uni.navigateTo({
					url: '/pages/my/myWallet/myWallet'
				})
			},
			toOrganization() {
				if (this.Institution) {
					uni.navigateTo({
						url: '/pages/my/organization/organization'
					})
				} else {
					uni.navigateTo({
						url: '/pages/my/organization/organizationEdit?id=' + 1
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.allBac {
		background-color: #f2f2f2;
	}

	.headers {
		padding: 0 15px 0 15px;
		background-image: url('../../static/img/my_img_top_bg.png');
		background-size: 100%;
		background-repeat: no-repeat;

		.btns {
			margin-top: 40rpx;
			height: 40px;
			line-height: 40px;
			font-size: 15px;
			font-weight: bold;
			display: flex;
			justify-content: flex-end;

			.servies {
				margin-right: 15px;
			}

			.setting {
				margin-right: 15px;
			}
		}

		.userInfo {
			height: 250px;

			// background-color: teal;
			.basicInfo {
				margin-top: -60rpx;
				height: 140px;
				// background-color: yellowgreen;
				display: flex;
				align-items: center;
				padding: 0 10px;

				.head_photo {
					width: 140rpx;
					height: 140rpx;
					background-color: #ffffff;
					border-radius: 70rpx;
				}

				.user_name {
					margin-left: 20px;
					font-size: 20px;
					color: #FFFFFF;

					.realName {
						font-weight: bold;
					}
				}
			}

			.userOperate {
				margin-top: -20rpx;
				height: 100px;
				background-color: #ffffff;
				border-radius: 16rpx;
				display: flex;
				justify-content: space-around;
				align-items: center;

				.operate1 {
					padding: 5px;
					width: 20%;
					height: 70px;
					border-radius: 5px;
					text-align: center;

					.text {
						font-size: 14px;
						font-weight: 500;
					}
				}
			}
		}
	}

	.myOrder {
		padding: 0 15px;
		margin-top: -5px;

		.orderTitle {
			border-radius: 16rpx 16rpx 0 0;
			height: 60px;
			background-color: #ffffff;
			display: flex;
			justify-content: space-between;
			line-height: 60px;
			padding: 0 15px;
		}

		.orderBtns {
			border-radius: 0 0 16rpx 16rpx;
			height: 100px;
			background-color: #ffffff;
			display: flex;
			justify-content: space-around;
			align-items: center;

			.orderBtn1 {
				width: 20%;
				height: 70px;
				border-radius: 5px;
				text-align: center;
			}
		}
	}

	.myFriend {
		margin-top: 5px;
		padding: 10px 15px 0 15px;
		border-radius: 16rpx;

		.friendTitle {
			border-radius: 16rpx 16rpx 0 0;
			height: 60px;
			background-color: #ffffff;
			display: flex;
			justify-content: space-between;
			line-height: 60px;
			padding: 0 15px;
		}

		.friendBtns {
			border-radius: 0 0 16rpx 16rpx;
			height: 100px;
			background-color: #ffffff;
			// border-radius: 10px;
			display: flex;
			justify-content: left;
			align-items: center;

			.blueBtn {
				width: 20%;
				margin-left: 10px;

				.btn_i {
					width: 100rpx;
					height: 100rpx;
					background-image: linear-gradient(#75B0FF, #5398F6);
					border-radius: 50rpx;
					text-align: center;
					line-height: 100rpx;
					color: #FFFFFF;
					font-size: 32rpx;
					;
				}
			}

			.addBtn {
				width: 20%;
				height: 100rpx;
				background-color: #ffffff;
				border-radius: 35px;
				line-height: 100rpx;
				margin-left: 10px;
			}
		}
	}

	.changes {
		margin-top: 10px;
		height: 100px;
		background-color: #ffffff;
		line-height: 100px;
		font-size: 18px;
		font-weight: bold;
		padding: 0 10px;
	}
</style>